<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>待办事项</title>
    <script src="./vue.js"></script>
    <style>
        #todo li{
            position: relative;
            width: 300px;
        }
        #todo li button{
            position: absolute;
            top: 0;
            right: 0;
        }


        .finish{
            text-decoration: line-through;
        }
    </style>
</head>
<body>
    <div id="app">
        <h1>待办事项</h1>
        <!-- 第一部分，记录 -->
        <input type="text" id="inp" placeholder="请输入待办事项" >
        <button type="button" v-on:click="save()">保存</button>
        <!-- 第二部分，待办事项 -->
        <p>待办事项：</p>
        <ol id="todo">
           <li v-for="(item,index) in val1" > {{item}}<button  type="button" v-on:click="doIt(index)" >完成</button></li>
        </ol>
        <!-- 第三部分，完成事项 -->
        <p>已完成事项：</p>
        <ol class="done">
            <li v-for="item in val2" class="finish">{{item}}</li>
        </ol>
    </div>

    <script>
        let vm = new Vue({
            el:'#app',
            data:{
                val1: [],
                val2: []
            },
            methods:{
                save(){
                   vm.val1.push(inp.value);
                   inp.value= '';

                },

                doIt(index){     
                    vm.val2.push(this.val1[index]);
                    vm.val1.splice(index,1);
                    console.log(this.val2);

                }
            }


        })
    </script>
</body>
</html>